package com.aurora.oa.message.presenter;


import android.util.Log;

import com.aurora.oa.Constants.AuroraConstants;
import com.aurora.oa.bean.HttpResult;
import com.aurora.oa.listener.OnRequestHttpDataListener;
import com.aurora.oa.message.bean.MessageData;
import com.aurora.oa.message.bean.MyReceiveMessageBean;
import com.aurora.oa.message.view.MessageListActivityView;
import com.aurora.oa.model.RequestHttpModel;
import com.aurora.oa.model.RequestHttpModelImpl;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import java.lang.reflect.Type;
import java.util.List;

/**
* Created by Administrator on 2017/03/27
*/

public class MessageListActivityPresenterImpl implements MessageListActivityPresenter{

    MessageListActivityView view;
    RequestHttpModel requestHttpModel;

    public MessageListActivityPresenterImpl(MessageListActivityView view) {
        this.view = view;
        requestHttpModel = new RequestHttpModelImpl();
    }

    public void getMessageData(int type, final int page){
        requestHttpModel.requestHttpDataString(AuroraConstants.GET_MESSAGE_MYRECEIVE + "/" + type + "/" + page, new OnRequestHttpDataListener() {
            @Override
            public void onRequestDataSuccess(String body) {
                Log.e("log_data",body);
                Gson gson = new Gson();
                Type messageDataType = new TypeToken<HttpResult<List<MyReceiveMessageBean>>>(){}.getType();
                HttpResult<List<MyReceiveMessageBean>> mdata = gson.fromJson(body,messageDataType);
                List<MyReceiveMessageBean> messageList = mdata.obj;
                if(page==0){
                    view.doPullDownRefresh(messageList);
                }else{
                    view.doPullUpLoad(messageList);
                }

            }

            @Override
            public void onRequestDataFail(String message) {
                view.onRequestDataFail();
            }
        });
    }
}